/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package beans;


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.Stateful;
import javax.interceptor.Interceptors;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Anneleen
 */
@Stateful

public class pageCount implements pageCountLocal {

    private int count;
    private HttpSession session;

    @Override
    @Interceptors(InterceptorLogger.class)
    public void increment() {
        count++;
    }
    
    @Override
    public int getCount() {
        return count;
    }
    
    @Override
    public void reset() {
        count = 0;
    }

    @Override
    @PreDestroy
    public void destroySession() {
        System.out.println("Stateful bean is destroyed: " + getDate());
        session.invalidate();
    }
    
    @Override
    public void setSession(HttpSession session) {
        this.session = session;
    }

    @PostConstruct
    @Override
    public void initialize() {
        System.out.println("Stateful bean is created: " + getDate());
    }

    @Override
    public String getDate() {
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date date = new Date();
        return dateFormat.format(date);
    }
    
    
}
